From 5e9dde9c591d3841a513610b6c295d342fd4c6cb Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Sun, 18 Sep 2005 20:49:58 +0000 Subject: [PATCH] list_each and babl_ticks() --- ChangeLog | 50 ++++++++++++++++++++++++++++++ babl/babl-classes.h | 74 ++++++++++++++++++++++++++++++--------------- babl/babl-util.c | 40 ++++++++++++++++++++++++ babl/babl-util.h | 6 ++++ 4 files changed, 145 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index b97e751..39d5943 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,53 @@ +2005-09-18 Øyvind Kolås + + * babl/Makefile.am: + * babl/babl-classes.h: + * babl/babl-conversion.c: (each_babl_conversion_destroy), + (conversion_new), (create_name), (babl_conversion_new), + (babl_conversion_process), (test_create), (babl_conversion_error): + * babl/babl-core.c: (rgba_to_rgba), (babl_core_init): + * babl/babl-db.c: (babl_db_count): + * babl/babl-db.h: + * babl/babl-extension.c: + * babl/babl-fish.c: (match_conversion), (babl_conversion_find), + (babl_fish_db), (babl_fish), (babl_fish_process), + (each_babl_fish_destroy): + * babl/babl-format.c: (babl_format_new), (babl_formats_count), + (babl_format_with_model_as_type), (test_create), + (babl_format_loss): + * babl/babl-internal.c: (babl_process), (each_conversion), + (each_format), (gen_type_format_for_model), + (gen_formats_for_model), (babl_extension_post_load): + * babl/babl-internal.h: + * babl/babl-introspect.c: (conversion_introspect): + * babl/babl-model.c: (babl_model_new), (test_create), + (reference_format), (construct_double_format), + (babl_model_is_symmetric): + * babl/babl-sanity.c: (id_sanity): + * babl/babl-type.c: (babl_type_new), (r_interval), (test_init), + (double_vector_format), (babl_type_is_symmetric): + * babl/babl-util.c: (babl_list_each), (init_ticks), (babl_ticks): + * babl/babl-util.h: + * babl/base/model-cmyk.c: (rgb_to_cmyk), (cmyk_to_rgb), + (conversions), (formats): + * babl/base/model-gray.c: (rgba_to_graya), (rgba_to_gray), + (graya_to_rgba), (gray_to_rgba), (conversions): + * babl/base/model-rgb.c: (formats): + * babl/base/model-ycbcr.c: (rgba_to_ycbcra), (rgba_to_ycbcr), + (ycbcra_to_rgba), (ycbcr_to_rgba), (conversions), (formats): + * docs/Makefile.am: + * docs/index-static.html.in: + * extensions/CIE-Lab.c: (rgba_to_lab), (lab_to_rgba), + (rgba_to_laba), (laba_to_rgba), (conversions): + * extensions/Makefile.in: + * extensions/naive-CMYK.c: (init), (rgba_to_cmyk), (cmyk_to_rgba): + * tests/Makefile.am: + * tests/babl-html-dump.c: (main): + * tests/conversions.c: (each_conversion), (main): + * tests/formats.c: (format_check), (main): + * tests/models.c: (model_check), (main): + * tests/types.c: (type_check), (main): + 2005-09-18 Øyvind Kolås * babl/babl.c: (babl_init), diff --git a/babl/babl-classes.h b/babl/babl-classes.h index d6adbb9..007ba97 100644 --- a/babl/babl-classes.h +++ b/babl/babl-classes.h @@ -43,20 +43,6 @@ typedef long (*BablFuncPlanar) (int src_bands, int dst_pitch[], long n); -#if 0 -typedef long (*BablFuncPlanarBit) (int src_bands, - void *src[], - int src_bit[], - int src_pitch[], - int src_bit_pitch[], - int dst_bands, - void *dst[], - int dst_bit[], - int dst_pitch[], - int dst_bit_pitch[], - long n); -#endif - /* magic number used at the start of all babl objects, used to do * differentiation in polymorphic functions. (as well as manual * type check assertions). @@ -81,6 +67,7 @@ typedef enum { BABL_FISH, BABL_FISH_REFERENCE, BABL_FISH_SIMPLE, + BABL_FISH_PATH, BABL_IMAGE, BABL_EXTENSION, @@ -106,7 +93,7 @@ BablConversion { BablInstance instance; union Babl *source; union Babl *destination; - int time_cost; + int cost; double error; union { @@ -202,6 +189,13 @@ typedef struct int *stride; } BablImage; +/* BablFish base class, the user of babl is just requesting a + * conversion, after that an appropriate species of fish is + * constructed to handle the request. + * + * TODO: + * * implement + */ typedef struct { BablInstance instance; @@ -211,6 +205,37 @@ typedef struct long pixels; } BablFish; + + +/* BablFishSimple is the simplest type of fish, wrapping a single + * conversion function, (note this might not be the optimal chosen + * conversion even if it exists) + */ +typedef struct +{ + BablFish fish; + BablConversion *conversion; +} BablFishSimple; + + + +/* BablFishPath is a combination of registered conversions, both + * from the reference types / model conversions, and optimized paths. + * + * This is the most advanced scheduled species of fish, some future + * version of babl might even be evovling combined fishes in a background + * thread, based on profiled usage. For this to work in a future version + * transmogrification between the fish classes would be used. + */ +typedef struct +{ + BablFish fish; + double cost; + double loss; + BablConversion *conversion[BABL_MAX_PATH_LENGTH]; + int conversions; +} BablFishPath; + /* BablFishReference on the double versions of conversions * that are required to exist for maximum sanity. * @@ -222,21 +247,19 @@ typedef struct * implementation is meant to be kept as small as possible wrt logic. * * One of the contributions that would be welcome are new fish factories. + * + * TODO: + * * cache the looked up conversions, removing all overhead but the + * actual conversions. + * * make optimal use of a single allocation containing enough space + * for the maximum amount of memory needed in to adjecant buffers + * at any time. */ typedef struct { BablFish fish; } BablFishReference; -/* BablFishSimple is the simplest type of fish, wrapping a single - * conversion function - */ -typedef struct -{ - BablFish fish; - BablConversion *conversion; -} BablFishSimple; - typedef struct { BablInstance instance; /* path to .so / .dll is stored in instance name */ @@ -256,8 +279,9 @@ typedef union BablConversion conversion; BablImage image; BablFish fish; - BablFishReference reference_fish; + BablFishReference fish_reference; BablFishSimple fish_simple; + BablFishPath fish_path; BablExtension extension; } Babl; diff --git a/babl/babl-util.c b/babl/babl-util.c index 8df5839..182f5e3 100644 --- a/babl/babl-util.c +++ b/babl/babl-util.c @@ -60,3 +60,43 @@ babl_add_ptr_to_list (void ***list, (*list)[orig_len+1]=NULL; } +void +babl_list_each (void **list, + BablEachFunction each_fun, + void *user_data) +{ + int i; + if (!list) + return; + for (i=0; i < list_length (list); i++) + { + if (each_fun ((Babl*) list[i], user_data)) + break; + } +} + +#include +#include + +static struct timeval start_time; +static struct timeval measure_time; + +#define msecs(time) ((time.tv_sec-start_time.tv_sec)*1000 + time.tv_usec/1000) + +static void +init_ticks (void) +{ + static int done=0; + if (done) + return; + done=1; + gettimeofday (&start_time, NULL); +} + +unsigned int +babl_ticks (void) +{ + init_ticks (); + gettimeofday (&measure_time, NULL); + return msecs(measure_time) - msecs(start_time); +} diff --git a/babl/babl-util.h b/babl/babl-util.h index 97b0816..9fa1176 100644 --- a/babl/babl-util.h +++ b/babl/babl-util.h @@ -23,4 +23,10 @@ void babl_add_ptr_to_list (void ***list, void *new); +void +babl_list_each (void **list, + BablEachFunction each_fun, + void *user_data); + +unsigned int babl_ticks (void); #endif -- 2.30.2